package com.yanh.product.controller;


import com.yanh.jcommon.utils.PageUtils;
import com.yanh.jcommon.utils.R;
import com.yanh.product.entity.SkuInfoEntity;
import com.yanh.product.service.SkuInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Tag(name="SkuInfo接口",description = "SkuInfo接口")
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @Operation(summary = "SkuInfo列表",description = "SkuInfo列表")
    @PostMapping("/list")
    public R list(@RequestBody List<Long> skuIds){

        var vos = skuInfoService.getSkuInfoList(skuIds);
        return R.ok().put("skuInfoList", vos);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }


    /**
     * 根据skuId查询当前商品的价格
     * @param skuId
     * @return
     */
    @GetMapping(value = "/{skuId}/price")
    public BigDecimal getPrice(@PathVariable("skuId") Long skuId) {

        //获取当前商品的信息
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        //获取商品的价格
        BigDecimal price = skuInfo.getPrice();

        return price;
    }
}
